#include <iostream>
#include<sys/time.h>
#include<unistd.h>
using namespace std;
int* a, * b;
const int n = 300000;//规定是偶数，方便二路算法计算

int main()
{
    a = new int [n];
    b = new int[n];
    //初始化记录数据的数组
    for (int i = 0; i < n; i++)
    {
        a[i] = rand() % 100;
        b[i] = a[i];
    }

    //二重循环
    struct timeval start4;
    struct timeval end4;
    gettimeofday(&start4, NULL);
    for (int m = n; m > 1; m /= 2)
        for (int i = 0; i < m / 2; i++)
            a[i] = a[i * 2] + a[i * 2 + 1];
    gettimeofday(&end4, NULL);
    cout << "二重循环耗时: " << end4.tv_sec - start4.tv_sec << "ms" << endl;

}